<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  const arr = [1, 2, 3, 4, 5, 6];
  function fn(...b) {
    let a = b.reduce((pre, cur) => pre += cur, 0);
    console.log(this, b, a);
  };
  // fn(...arr); //window   [1, 2, 3, 4, 5, 6]  21

  const obj = {
    name: '张三',
  };

  const res1 = fn.call(obj, 1, 2); //obj [1,2] 3
  fn.apply(obj, [1, 2]); //obj [1,2] 3 
  const res = fn.bind(obj);
  console.log(res); //  bind传参后不会立刻执行，会返回一个改变this指向的函数，这个函数还是可以传参的 bind()()
  // fn(...b) {
  //   let a = b.reduce((pre, cur) => pre += cur, 0);
  //   console.log(this, b, a);
  // }

  res(1, 2)//obj [1,2] 3
</script>

</html>